<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        Zend_Registry::get('layout')->setLayout('index');
        
        $activeResource=$this->getRequest()->getControllerName();
        
        // seting active resource
        Zend_Registry::set('resource',$activeResource);
        
        $this->view->headTitle()->append(Zend_Registry::get('locale')->_('Home'));
        
        $this->view->headMeta()->appendName('keywords', '')
                               ->appendName('description', '');
                           
        
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->flash_messages = $this->_flashMessenger->getMessages();
    }

    public function indexAction()
    {
        if (!Zend_Registry::get('user')->canView(new Application_Model_UserResources(Application_Model_UserResources::getFrontResource())))
        {
            return ;
        }
        
        $key=(int) $this->_getParam('key');
        
        $cache=Zend_Registry::get('cache');
        
        if(!$nodes = $cache->load('frontpage_'.$key)) 
        {
            $nodeTbl=new Application_Model_NodeDb();
            
            list($nodes,$paginator)=$nodeTbl->getFrontNodesPage($key,5,true);
            
            $cache->save($nodes, 'frontpage_'.$key);
        }
        
        $this->view->nodes=$nodes;
    }
}

